<template>
  <div class="warn-info">
    <Tooltip :content="`未确认报警信息${countComputed}条`" placement="bottom">
      <Badge :type="countComputed === 0 ? 'success' : 'error'" :count="countComputed" show-zero>
        <Button type="text" @click="openWarnPage">
          <Icon :size="20" type="md-alert"/>
        </Button>
      </Badge>
    </Tooltip>
  </div>
</template>

<script>
import { mapMutations } from 'vuex'
export default {
  name: 'WarnInfo',
  inject: ['openWarnModal'],
  props: {
    count: {
      type: Number,
      default: 0
    },
    hasRead: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    countComputed () {
      return this.hasRead ? 0 : this.count
    }
  },
  methods: {
    ...mapMutations([
      'addTag'
    ]),
    openWarnPage () {
      // this.$router.push({
      //   path: '/message/message-page'
      // })
      // this.openWarnModal()
      // this.$router.push({
      //   path: '/warn-query/realtime-warn'
      // })
      // let target = 'app/ai-warn-handle'
      // let newRoute = {}
      // let iframeRoutes = this.$store.state.user.iframeRoutes
      // for (let i = 0; i < iframeRoutes.length; i++) {
      //   if (iframeRoutes[i].meta.url.indexOf(target) !== -1) {
      //     newRoute = iframeRoutes[i]
      //     break
      //   }
      // }
      // this.$store.commit('setCurrentTabs', newRoute.meta.uuid)
      // const { name, query, params, meta } = newRoute
      // this.addTag({
      //   route: { name, query, params, meta },
      //   type: 'push'
      // })
      // sessionStorage.setItem('currentTabs', name)
      // let routes = this.$store.state.user.iframeRoutes
      // let names = this.$store.state.user.iframeNames
      // // console.log(names, name)
      // let index = names.indexOf(name)
      // if (index !== -1) {
      //   this.$set(routes[index], 'ifRender', true)
      //   this.$store.commit('setIframeRoutes', routes)
      // }
    }
  }
}
</script>

<style lang="stylus" scoped>
.warn-info
  margin-right 12px
  & >>> .ivu-badge-count
    top 10px
  & >>> .ivu-btn.ivu-btn-text
    padding 5px 1px 6px
</style>
